#ifndef BUFFER_H
#define BUFFER_H
#define DEFAULT_BUFFER_SIZE 1024
#include <Windows.h>
class Buffer
{
public:
	Buffer(void);
	Buffer(Buffer const& rhs);
	~Buffer(void);

	char& operator		[](size_t pos) const;
	Buffer& operator	=(Buffer const& rhs);
	operator int(void) const;

	template <typename T> Buffer& operator	>>(T& buff)
	{
		Read(buff);
		return *this;
	}
	template <typename T> Buffer& operator << (T& buff)
	{
		Append(reinterpret_cast<char*> (&buff), sizeof(T));
		return *this;
	}
	template <typename T> Buffer& operator << (T const& buff)
	{
		Append(reinterpret_cast<char*> (const_cast<int*>(&buff)), sizeof(T));
		return *this;
	}
	bool Read(char* const buff, size_t len);
	bool Append(char const* const buff, size_t len);

	template <typename T> bool Read(T& buff)
	{
		return Read(reinterpret_cast<char*>(&buff), sizeof(T));
	}

	size_t GetSize(void) const;


private:
	char*				m_data;
	size_t				m_size;

	size_t				m_readPos;
	size_t				m_writePos;
	mutable CRITICAL_SECTION m_criticalSection;
};
#endif